package com.example.kaogong.sys.controller;


import com.example.kaogong.common.exception.ParamsErrorException;
import com.example.kaogong.common.utils.Assert;
import com.example.kaogong.common.utils.RespBean;
import com.example.kaogong.sys.pojo.dto.TagDto;
import com.example.kaogong.sys.pojo.vo.TagVo;
import com.example.kaogong.sys.service.ITagService;
import com.google.gson.Gson;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 课程标签 前端控制器
 * </p>
 *
 * @author    
 * @since 2022-03-26
 */
@RestController
@RequestMapping("/tag")
@Api(tags = "课程标签管理接口")
@Slf4j
public class TagController {
    @Autowired
    private ITagService tagService;

    @GetMapping(value = "/manage/tag")
    @ApiOperation(value = "获取所有课程标签")
    public RespBean<List<TagVo>> getAllTag() {
        RespBean<List<TagVo>> respBean = tagService.getAllTag();
        log.info("response:{}", new Gson().toJson(respBean));
        return respBean;
    }

    @PostMapping(value = "/manage/tag")
    @ApiOperation(value = "添加课程标签")
    public RespBean addTag(@Valid @RequestBody TagDto tagDto) {
        log.info("request:{}", new Gson().toJson(tagDto));
        RespBean respBean = tagService.addTag(tagDto);
        log.info("response:{}", new Gson().toJson(respBean));
        return respBean;
    }

    @DeleteMapping(value = "/manage/tag/{tagId}")
    @ApiOperation(value = "根据课程标签编号删除课程标签")
    public RespBean deleteTagByTagId(@PathVariable Integer tagId) {
        Assert.notNull(tagId, new ParamsErrorException("课程标签编号不能为空"));
        log.info("tagId:{}", tagId);
        RespBean respBean = tagService.deleteTagByTagId(tagId);
        log.info("response:{}", new Gson().toJson(respBean));
        return respBean;
    }
}
